<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

    class Object_lib{

        public function __construct(){

            $this->CI = &get_instance();
            $this->CI->load->model("objects_model");
            $this->CI->load->library('translate');
        }

        /**
        * 
        * Show error message
        * @param $str error string
        */        
        private function throwError($str){
            echo $str;
            exit();
        }

        public function edit_info($object_id,$content,$languages)
        {

            $count = count($languages);

            $k=0;
            $information = "";        

            foreach ($languages as $key=>$value):
                $information .= $this->CI->translate->create_field($key,$content[$k]);
                $k++;
                endforeach;

            $this->CI->objects_model->update($object_id, array('information'=>$information));

            return TRUE;
        } 

        public function find_id($object_id)
        {
            return $this->CI->objects_model->list_by_id($object_id);
        }

        //create language fields from input array[] in post
        public function parse_post($post,$languages)
        {
            $information = "";

            foreach ($post as $key=>$value):
                if(is_array($value)):

                    $k=0;
                    foreach ($languages as $key2=>$value2):
                        $information .= $this->CI->translate->create_field($key2,$post[$key][$k]);
                        $k++;
                        endforeach;

                    $post[$key]=$information;
                    $information = ""; 

                    endif;
                endforeach;

            return $post;
        }

    }

?>
